// src/router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import Posts from '@/components/Posts'
import Profile from '@/components/Profile'
import Header from '@/components/Header'
import Footer from '@/components/Footer'
import postDetail from '@/components/postDetail'
import Login from '@/components/Login'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Posts',
        components: {
            default: Posts,
            header: Header,
            footer: Footer
        }
    },
    {
        path: '/posts',
        components: {
            default: Posts,
            header: Header,
            footer: Footer
        },
        meta: { requiresAuth: true }
    },
    {
        path: '/profile',
        components: {
            default: Profile,
            header: Header,
            footer: Footer
        },
        meta: { requiresAuth: true }    // 添加路由元信息，表示需要登录才能访问
    },
    {
        path: '/postdetail',
        name: 'postDetail',
        components: {
            default: postDetail,
            header: Header,
            footer: Footer
        },
        meta: { requiresAuth: true }
    },
    {
        path: '/login',
        name: 'login',
        components: {
              default: Login,
              header: Header,
              footer: Footer
        }
    },
    {
        path: '*',
        redirect: '/posts' // 默认跳转到帖子列表
    }
  ]
})
